﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UFPE.CIn.Abc.Primality.Algorithms;
using UFPE.CIn.Abc.Primality.Util;

namespace FerramentaComparacao
{
    public class Testes
    {
        private Dictionary<String, IAlgorithm> algoritmos;

        private static Testes instance;

        public static Testes Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new Testes();
                }

                return instance;
            }
        }

        private Testes()
        {
            algoritmos = new Dictionary<string, IAlgorithm>();

            algoritmos.Add(TrialDivision.Instance.AlgorithmName, TrialDivision.Instance);
            algoritmos.Add(FermatPrimalityTest.Instance.AlgorithmName, FermatPrimalityTest.Instance);
            algoritmos.Add(SolovayStrassen.Instance.AlgorithmName, SolovayStrassen.Instance);
            algoritmos.Add(MillerRabin.Instance.AlgorithmName, MillerRabin.Instance);
            algoritmos.Add(LucasSelfridge.Instance.AlgorithmName, LucasSelfridge.Instance);
            algoritmos.Add(BailliePSW.Instance.AlgorithmName, BailliePSW.Instance);
            algoritmos.Add(AKS.Instance.AlgorithmName, AKS.Instance);
            algoritmos.Add(AKSL.Instance.AlgorithmName, AKSL.Instance);

            /*foreach (var item in algoritmos)
            {
                if (item.Key != TrialDivision.Instance.AlgorithmName || item.Key != AKS.Instance.AlgorithmName)
                {
                    item.Value.IsPrime(new BigInteger("72436547587663244567897324245678976532433445678654367384985694363453645476561", 10));
                }
            }*/
        }

        public List<string> GetAlgorithmNames()
        {
            List<string> retorno = new List<string>();

            foreach (KeyValuePair<string, IAlgorithm> item in algoritmos)
            {
                retorno.Add(item.Key);
            }

            return retorno;
        }

        public bool CallAlgorithm(string alg, BigInteger num)
        {
            return algoritmos[alg].IsPrime(num);
        }

        public long GetThreshold(string alg)
        {
            return algoritmos[alg].Threshold;
        }

        public long TimeLastRun(string alg)
        {
            return algoritmos[alg].TimeLastRun;
        }
    }
}
